home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / roids / lines.dist < prev    next >
Encoding:
Text File  |  1995-05-03  |  2.5 KB  |  77 lines

  1. /*
  2.  * Copyright 1989 Digital Equipment Corporation
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Digital Equipment
  9.  * Corporation not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  Digital Equipment Corporation makes no representations
  12.  * about the suitability of this software for any purpose.  It is
  13.  * provided "as is" without express or implied warranty.
  14.  *
  15.  * DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16.  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
  18.  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21.  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Terry Weissman
  24.  *          weissman@decwrl.dec.com
  25.  */
  26.  
  27. /* lines.c -- paint a bunch of lines with minimal requests. */
  28.  
  29. /* %%% Too lazy to compress these; maybe I'll do it later. */
  30.  
  31.  
  32. #include "roids.h"
  33.  
  34. void BeginLines() {}
  35.  
  36. void AddLine(fromx, fromy, tox, toy, gc)
  37. int fromx, fromy, tox, toy;
  38. GC gc;
  39. {
  40.     XDrawLine(dpy, gamewindow, gc, fromx, fromy, tox, toy);
  41. }
  42.  
  43. void EndLines() {}
  44.  
  45.  
  46. #define BETWEEN(x, a, b) ((a <= b && x >= a && x <= b) ||    \
  47.               (a > b && x <= a && x >= b))
  48.  
  49. Boolean CheckIntersects(ax, ay, bx, by, cx, cy, dx, dy)
  50. int ax, ay, bx, by, cx, cy, dx, dy;
  51. {
  52.     float m1, m2, b1, b2, x, y;
  53.     if (bx == ax) {
  54.     if (dx == cx) return FALSE; /* Parallel; hacking, assume they miss. */
  55.     m2 = ((float) (dy - cy)) / ((float) (dx - cx));
  56.     b2 = cy - cx*m2;
  57.     x = ax;
  58.     y = m2 * x + b2;
  59.     return (BETWEEN(y, ay, by) && BETWEEN(x, cx, dx) &&
  60.         BETWEEN(y, cy, dy));
  61.     }
  62.     if (dx == cx) {
  63.     return CheckIntersects(cx, cy, dx, dy, ax, ay, bx, by);
  64.     }
  65.     m1 = ((float) (by - ay)) / ((float) (bx - ax));
  66.     m2 = ((float) (dy - cy)) / ((float) (dx - cx));
  67.     b1 = ay - ax*m1;
  68.     b2 = cy - cx*m2;
  69.     if (m1 == m2) {        /* Parallel lines */
  70.     return FALSE;        /* Hack. */
  71.     }
  72.     x = (b2 - b1) / (m1 - m2);
  73.     y = m1 * x + b1;
  74.     return (BETWEEN(x, ax, bx) && BETWEEN(y, ay, by) &&
  75.         BETWEEN(x, cx, dx) && BETWEEN(y, cy, dy));
  76. }
  77.